//对象编程

let o1 = new Object();//调用构造函数 
let o2 = {};
let user = {
    name: "张三",
    age: 20,
};
user.role ="学生" ; //设置属性
delete user.role; //删除属性
console.log(user.name);
console.log(user);


//[]访问符
user["is admin" ] = true;
console.log(user["is admin"]);
let  a = "name";
console.log(user[a]);


//for...n 循环 遍历对象的属性名 
for(let key in user){
    console.log(key + ":" +user[key]);
}


//对象 对象的引用 
console.log();
let user1 = user;
user.age = 21;
console.log(user.age);
console.log(user1 === user);


//可选链  --->如果 user.features 有被定义就可以访问它的gender
console.log(user.features?.gender);

//浅层clone
user.features ={
    role:"student",
    gender :"male",
};
//通过遍历来clone对象
console.log();
let user2 = {}
for( let key in user){
    user2[key] = user[key]
}
console.log(user2)
console.log(user2 === user);


//内置对象那个Object的assign方法 ,clone对象
console.log();
let user3 = Object.assign({},user);
console.log(user3)
console.log(user3 === user);

user.features.gender = "female";
console.log(user2.features.gender);